﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AutoUnitTest.Common
{
    public static class StringExtention
    {
        const  string Dog = "@";
        const string Dot = ".";

        public static string NameSpace(this string self)
        {
            if (self.Contains(Dot))
                return self.Substring(0, self.LastIndexOf(Dot));
            return string.Empty;

        }

        public static string Type(this string self)
        {
            if (self.Contains(Dot))
            {
                int lastDotIndex = self.LastIndexOf(Dot);

                return self
                    .Substring(lastDotIndex, self.Length - lastDotIndex)
                    .Remove(0, 1);
            }
            return self;
        }

        public  static string RemoveDog(this string  self)
        {

            if (self.Contains(Dog) && self.IndexOf(Dog) == 0)
            {
                return self.Substring(0, 1) == Dog
                           ? self.Substring(1, self.Length - 1)
                           : self;
            }
            return self;
        }
    }
}
